package com.example.j280_webproject.day039.servlet;

import com.example.j280_webproject.day039.service.SelectClassListService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@WebServlet("/selectClassList")
public class SelectClassListServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String className = req.getParameter("className");
        SelectClassListService selectClassListService = new SelectClassListService();
        List<com.example.j280_webproject.day039.pojo.Class> list = selectClassListService.selectClassList(className);
        resp.setContentType("text/html;charset=utf-8");
        PrintWriter writer = resp.getWriter();
        if (list==null){
            writer.print("系统繁忙请稍后再试！");
            return;
        }
        if(list.size() == 0) {
            writer.print("对不起，没有查询匹配的内容！");
            return;
        }
        writer.print("班级ID" + "   "  + "班级名称" + "<br/>");
        for (com.example.j280_webproject.day039.pojo.Class myClass : list){
           writer.print(myClass.id+"  "+myClass.className+"<br/>");
        }
    }
}
